package com.atguigu.lease.admin.controller;

import com.atguigu.lease.admin.service.LeaseTermService;
import com.atguigu.lease.common.result.Result;
import com.atguigu.lease.model.bean.LeaseTerm;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author LOGIN
 * @title LeaseTermController
 * @create 2025/6/23 0:45
 * @description
 */
@Tag(name= "房间租期管理")
@RestController
@RequestMapping("/admin/term")
public class LeaseTermController {
    @Autowired
    LeaseTermService leaseTermService;
    @GetMapping("/list")
    @Operation(summary = "1、查询所有房间租期")
    public Result<List<LeaseTerm>> list() {
        return Result.ok(leaseTermService.list());
    }

    ///admin/term/saveOrUpdate
    @Operation(summary = "2、新增或者更新房间租期")
    @PostMapping("/saveOrUpdate")
    public Result saveOrUpdate(
            @RequestBody LeaseTerm leaseTerm) {
        return Result.ok(leaseTermService.saveOrUpdate(leaseTerm));
    }
    ///admin/term/deleteById?id=7
    @DeleteMapping("/deleteById")
    @Operation(summary = "3、删除房间租期")
    public Result deleteById(@Parameter(description = "主键值", in = ParameterIn.QUERY,required = true) @RequestParam("id") Integer id) {
        return Result.ok(leaseTermService.removeById(id));
    }


}
